package com.geovis.emergency.spd.controller.pc;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.geovis.common.core.api.Result;
import com.geovis.common.core.constant.SwaggerConstants;
import com.geovis.common.core.controller.BaseController;
import com.geovis.emergency.spd.biz.pc.service.IPcSchedulingEventService;
import com.geovis.emergency.spd.biz.pc.service.IPcSchedulingEventSituationService;
import com.geovis.emergency.spd.biz.pc.service.IPcSchedulingEventStatisticsService;
import com.geovis.emergency.spd.entity.pc.entity.PcSchedulingEvent;
import com.geovis.emergency.spd.entity.pc.entity.PcSchedulingEventSituation;
import com.geovis.emergency.spd.entity.pc.pojo.vo.PcSchedulingEventVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/10/25
 */
@RestController
@RequestMapping("/pc/scheduling/event")
@RequiredArgsConstructor
@Api(value = "应急预案指挥模块-指挥调度事件接口", tags = "应急预案指挥模块-指挥调度事件接口")
@Slf4j
@Validated
public class PcSchedulingEventController extends BaseController<IPcSchedulingEventService> {

    private final IPcSchedulingEventSituationService pcSchedulingEventSituationService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = SwaggerConstants.LIST_VALUE, notes = SwaggerConstants.LIST_VALUE)
    @GetMapping("/list")
    public Result<List<PcSchedulingEvent>> list(){
        return Result.ok(baseService.list(
                Wrappers.lambdaQuery(PcSchedulingEvent.class)
                        .orderByDesc(PcSchedulingEvent::getSubmitTime))
        );
    }
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = SwaggerConstants.GET_BY_ID_NOTES, notes = SwaggerConstants.GET_BY_ID_NOTES)
    @GetMapping("/detail/{pcDrillId}")
    public Result<PcSchedulingEventVO> detail(@PathVariable("pcDrillId") String pcDrillId){
        PcSchedulingEventVO detail = baseService.getDetailEventByDrillId(pcDrillId);
        return Result.ok(detail);
    }
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = SwaggerConstants.SAVE_VALUE, notes = SwaggerConstants.SAVE_VALUE)
    @PostMapping("/save")
    public Result save(@RequestBody PcSchedulingEventVO schedulingEventVO){
        pcSchedulingEventSituationService.saveDetail(schedulingEventVO);
        return Result.ok();
    }
}
